#include "Custom.h"
#include "./ui_dialog.h"


Custom::Custom(QWidget *parent) :
        QDialog(parent), ui(new Ui::Dialog) {
    ui->setupUi(this);
    connect(ui->spinBox_r, &QSpinBox::valueChanged, ui->horizontalSlider_r, &QSlider::setValue);
    connect(ui->horizontalSlider_r, &QSlider::valueChanged, ui->spinBox_r, &QSpinBox::setValue);
    connect(ui->spinBox_c, &QSpinBox::valueChanged, ui->horizontalSlider_c, &QSlider::setValue);
    connect(ui->horizontalSlider_c, &QSlider::valueChanged, ui->spinBox_c, &QSpinBox::setValue);
    connect(ui->spinBox_n, &QSpinBox::valueChanged, ui->horizontalSlider_n, &QSlider::setValue);
    connect(ui->horizontalSlider_n, &QSlider::valueChanged, ui->spinBox_n, &QSpinBox::setValue);
    connect(ui->spinBox_r, &QSpinBox::valueChanged, this, &Custom::setMax);
    connect(ui->spinBox_c, &QSpinBox::valueChanged, this, &Custom::setMax);
}

Custom::~Custom() {
    delete ui;
}

void Custom::setConfig(int r, int c, int n) {
    ui->spinBox_r->setValue(r);
    ui->horizontalSlider_r->setValue(r);
    ui->spinBox_c->setValue(c);
    ui->horizontalSlider_c->setValue(c);
    ui->spinBox_n->setValue(n);
    ui->horizontalSlider_n->setValue(n);
    setMax();
}

std::tuple<int, int, int> Custom::getConfig() {
    return {
            ui->spinBox_r->value(),
            ui->spinBox_c->value(),
            ui->spinBox_n->value(),
    };
}

void Custom::setMax() {
    int max = ui->spinBox_r->value() * ui->spinBox_c->value() - 1;
    ui->spinBox_n->setMaximum(max);
    ui->horizontalSlider_n->setMaximum(max);
}